<?php
use Base\AdminController;
use Illuminate\Support\Str;
use JetBrains\PhpStorm\NoReturn;

class ExamController extends AdminController
{

    /**
     * 初始化
     */
    #[NoReturn] public function init(): void
    {
        $this->routeWhiteLst = ['exam@testpaper'];
        parent::init();
    }

    /**
     * 获取列表页数据
     * @return void
     */
    #[NoReturn] public function testPaperAction(): void
    {
        try {
            $test = ExamTopicModel::query()->with(["options"])->get()->toArray();
            foreach ($test as $key=>$vo) {
                foreach ($vo['options'] as $k=>$v) {
                    $test[$key]['options'][$k]['is_check'] =  0;
                }
            }
            $result = [
               [
                   'id'=>1,
                   'title'=>'基础试题(单选)',
                   'score'=>count($test),
                   'test'=>$test
               ]
            ];
            $this->apiSuccess($result,"获取成功",20000);
        }catch (Exception $exception) {
            Log::$customFileName = LOG_PATH."/errors/";
            Log::error($exception->getMessage().$exception->getTraceAsString());
            $this->apiError($exception->getMessage());
        }
    }

}
